package com.ittest.service.impl;

import com.ittest.mapper.DeptMapper;
import com.ittest.pojo.Dept;
import com.ittest.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    /**
     * 新增部门操作
     */
    @Override
    public boolean addDept(Dept dept) {
        return deptMapper.addDept(dept);
    }

    /**
     * 删除部门操作
     *
     * @param id
     */
    @Override
    public boolean deleteDept(Integer id) {
        //TO Do
        Integer count = deptMapper.count(id);
        // 部门下员工数为0,该部门可以被删除
        if (count==0){
            return deptMapper.deleteDept(id);
        }else{
            return false;
        }
    }

    /**
     * 修改部门操作
     *
     * @param dept
     */
    @Override
    public boolean updateDept(Dept dept) {
        return deptMapper.updateDept(dept);
    }

    /**
     * 查询所有操作
     *
     * @return
     */
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }
}
